  import {
      getRoleList
  } from './models/getRoleList.model';
  import {
      createView
  } from './views/create.view';
  import {
      validate
  } from './validate';
  import {
      submit
  } from './submit';
  import {
      modal7
  } from '../common/layer';


  const createBtnHandler = () => {

      getRoleList('-1', function (data) {

          modal7('新增', createView(data));

          $(".modal-form input").iCheck({
              checkboxClass: 'icheckbox_minimal-blue',
              radioClass: 'iradio_minimal-blue'
          });

          $('#submitBtn').click(() => {
              let data = {};
              $.each($('#form').serializeArray(), (key, val) => {
                  data[val.name] = val.value;
              });

              let roleid = $('#rolelist .checked input').val();
              data.roleid = roleid;
              if (!validate(data)) {
                  return;
              }
              submit(GLOBAL_adminAddUrl, data);
          });

      });


  };

  export {
      createBtnHandler
  }